﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using Utils;
using Settings;
using System.Data;

namespace PanasonicWarranty.DAL
{
    public partial class DBSysUserGroup
    {
        public static SqlDataReader GetByUserIDAndGroupID(int UserID, int GroupID)
        {
            try
            {
                return SqlHelper.ExecuteReader(CommonSetting.ConnectionString, CommandType.Text, string.Format("SELECT * FROM SysUserGroup WHERE UserID = {0} AND GroupID = {1}", UserID, GroupID));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static bool Create1(int UserID, int GroupID)
        {
            try
            {
                using (SqlConnection conn = new SqlConnection(CommonSetting.ConnectionString))
                {
                    int result = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, string.Format("INSERT INTO SysUserGroup (UserID,GroupID) VALUES ({0},{1})", UserID, GroupID));
                    return (result > 0);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static bool Delete1(int UserID, int GroupID)
        {
            try
            {
                using (SqlConnection conn = new SqlConnection(CommonSetting.ConnectionString))
                {
                    int result = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, string.Format("DELETE FROM SysUserGroup WHERE UserID = {0} AND GroupID = {1}", UserID, GroupID));
                    return (result > 0);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
